source('code/analysis/load.R')
calculate_mc = function(data) {
  data = data %>% 
    filter(attention==1) %>% 
    mutate(across(starts_with('mc'), function(x) recode(as.numeric(x), `2`=0, `1`=1))) %>% 
    mutate(mc_score = -(mc_1+mc_2+mc_3+mc_4-mc_5+mc_6-mc_7+mc_8-mc_9-mc_10+mc_11+mc_12+mc_13))
  return(data)
}

# general population sample 
general_mc = haven::read_dta('data/raw/sanctions.dta') %>% 
  filter(attention==1) %>% 
  calculate_mc() %>% 
  mutate(sample='General population') %>% 
  dplyr::select(sample, mc_score)

general_mean = mean(general_mc$mc_score, na.rm=T)
general_sd = sd(general_mc$mc_score, na.rm=T)

daylight = haven::read_dta('data/working/daylight-sender.dta') %>% 
  filter(attention==1, !is.na(mc_score)) %>% 
  dplyr::select(mc_score, join, posted)

mc_compare = daylight %>% 
  mutate(sample='Logged in via Tweetability') %>% 
  bind_rows(daylight %>% filter(join==1) %>% mutate(sample='Joined campaign')) %>% 
  bind_rows(daylight %>% filter(posted==1) %>% mutate(sample='Posted Tweet')) %>% 
  bind_rows(general_mc) %>% 
  mutate(mc_score = (mc_score-general_mean)/general_sd) %>% 
  group_by(sample) %>% 
  summarise(mean = mean(mc_score, na.rm=T),
            se = sd(mc_score, na.rm=T)/sqrt(n())) %>% 
  mutate(sample = factor(sample, levels=rev(c('General population','Logged in via Tweetability','Joined campaign','Posted Tweet'))))


plot = ggplot(mc_compare, aes(x = sample, y = mean)) +
  geom_point(size=3) +
  geom_linerange(aes(ymin = mean-1.96*se, ymax=mean+1.96*se), alpha=0.3, size=0.8) + 
  theme_bw() +
  theme(axis.title.x = element_blank()) + 
  ylab('Marlowe-Crowne score (z-score)') +
  ylim(c(-0.25,0.25))

ggsave('output/figures/marlowe-crowne.png', plot=plot, width=7, height=3.5)
